#include "DDisplay.h"
#include <iostream>
#include <cstdio>

using namespace pezad;
using namespace std;

void interpretEvents() {
	SDL_Event event;

	SDL_PollEvent(&event);
	if(event.type == SDL_MOUSEMOTION){
		cout << "Mouse horizontal: " << event.motion.x << endl;
	}
	if(event.type == SDL_KEYUP)
	{
		SDLKey released = event.key.keysym.sym;
		if(released == SDLK_q || released == SDLK_ESCAPE)
		{
			cout << "Wants to quit!" << endl;
		}
	}
	else if(event.type == SDL_QUIT)
	{
//		wantsToQuit = true;
		cout << "Wants to quit!" << endl;
	}
	else if(event.type == SDL_VIDEORESIZE)
	{
		Uint16 newWidth = event.resize.w;
		Uint16 newHeight = event.resize.h;
		SDL_Surface *screen;
		screen = SDL_SetVideoMode(newWidth, newHeight, 0, SDL_DOUBLEBUF | SDL_ANYFORMAT | SDL_RESIZABLE);
		if (screen == NULL) {
			cerr << "Unable to resize video: " << SDL_GetError() << endl;
		}
	}
}

int main(int argc, char *argv[]) {

	DDisplay &display = DDisplay::getInstance();
	
	Uint32 endingTicks = SDL_GetTicks() + 10000;
	
	while(SDL_GetTicks() < endingTicks) {
		interpretEvents();
		display.renderFrame();
	}


	SDL_Quit(); // Shut down SDL nicely.
	cout << "Success!" << endl;

	return EXIT_SUCCESS;
}
